package day13_net.com.itheima.d6_tcp3;

import java.io.DataInputStream;
import java.io.InputStream;
import java.net.Socket;

public class ServerReaderThread extends Thread{
    private Socket socket;
    public ServerReaderThread(Socket socket) {
        this.socket = socket;
    }

    @Override
    public void run() {
        try {
            InputStream is = socket.getInputStream();
            DataInputStream dis = new DataInputStream(is);
            while (true){
                System.out.println("dis.readUTF() = " + dis.readUTF());
                System.out.println("socket.getInetAddress().getHostAddress() = " + socket.getInetAddress().getHostAddress());
                System.out.println("socket.getPort() = " + socket.getPort());
            }
        }catch (Exception e){
            e.printStackTrace();
            System.out.println(socket.getInetAddress().getHostAddress() + ": " + socket.getPort() + " 下线了");
        }
    }
}
